package com.geoway.adf.report.po;

import com.geoway.adf.report.excel.workbook.WorkBook;
import com.vladmihalcea.hibernate.type.json.JsonType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @Author: lzw
 * @Date: 2024/1/12 16:09
 * @Description: workbook对象
 */
@Entity
@Table(name="adf_report_excel")
@TypeDef(name = "jsonType", typeClass = JsonType.class)
public class WorkBookPO extends BaseEntity implements Serializable {

    /**
     * Excel编号
     */
    @Id
    @Column(name="id")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "simpleUUID")
    @GenericGenerator(name = "simpleUUID", strategy = "com.geoway.adf.report.jpa.SimpleUUIDGenerator")
    private String excelId;

    /**
     * Excel名称
     */
    @Column(name="name",unique = true,nullable=false)
    private String excelName;

    /**
     * Excel配置选项
     */
    @Column(name="options",columnDefinition = "jsonb")
    @Type(type = "jsonType")
    private WorkBook workBook;

    public String getExcelId() {
        return excelId;
    }

    public void setExcelId(String excelId) {
        this.excelId = excelId;
    }

    public String getExcelName() {
        return excelName;
    }

    public void setExcelName(String excelName) {
        this.excelName = excelName;
    }

    public WorkBook getWorkBook() {
        return workBook;
    }

    public void setWorkBook(WorkBook workBook) {
        this.workBook = workBook;
    }

    @Override
    public String toString() {
        return "WorkBookPO{" +
                "excelId='" + excelId + '\'' +
                ", excelName='" + excelName + '\'' +
                ", workBook=" + workBook +
                "} " + super.toString();
    }

    public static WorkBookPO toWorkBookPO(WorkBook workBook){
        WorkBookPO workBookPO = new WorkBookPO();
        workBookPO.setExcelId(workBook.getGridKey());
        workBookPO.setExcelName(workBook.getTitle());
        workBookPO.setWorkBook(workBook);
        return workBookPO;
    }
}
